//
//  ViewController.m
//  14---UICollectionView
//
//  Created by 冀永金 on 16/8/2.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "ViewController.h"
#import "myCollectionCell.h"
@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((self.view.frame.size.width - 80) / 3, (self.view.frame.size.width - 80) / 3 * 1.618);
    layout.sectionInset = UIEdgeInsetsMake(10, 20, 10, 20);
    layout.minimumInteritemSpacing = 20;
    //layout.minimumLineSpacing = 20;
    layout.scrollDirection =  UICollectionViewScrollDirectionVertical; // 垂直方向滚动
  //  UICollectionViewScrollDirectionHorizontal 水平方向滚动
    // 区头大小
    layout.headerReferenceSize = CGSizeMake(100, 100);
    // 区尾大小
    layout.footerReferenceSize = CGSizeMake(200, 200);
    // 区头悬浮效果
    layout.sectionHeadersPinToVisibleBounds = YES;
    // 区尾悬浮效果
    layout.sectionFootersPinToVisibleBounds =NO;
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    collectionView.backgroundColor= [UIColor whiteColor];
    [self.view addSubview:collectionView];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [collectionView registerClass:[myCollectionCell class] forCellWithReuseIdentifier:@"pool"];
    collectionView.showsVerticalScrollIndicator = NO;
    [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"poolOfHeader"];
    [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"poolOfFooter"];
    // Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 3;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  myCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    cell.image.image = [UIImage imageNamed:@"报纸"];
    return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if (kind == UICollectionElementKindSectionHeader) {
        UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"poolOfHeader" forIndexPath:indexPath];
        
        header.backgroundColor = [UIColor redColor];
        return header;
    }else  {
        UICollectionReusableView *footer = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"poolOfFooter" forIndexPath:indexPath];
        footer.backgroundColor = [UIColor yellowColor];
        return footer;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
